import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path(.*)',
    component: () => import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () => import('@/views/login/auth-redirect'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () => import('@/views/error-page/401'),
  hidden: true
},
{
  path: '/',
  hidden: true,
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    component: () => import('@/views/phono/index'),
    name: '首页',
    meta: { title: '', icon: 'dashboard', affix: true }
  }]
}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [{
  path: '/CITest', // 集成测试
  component: Layout,
  redirect: '/CITest/home',
  alwaysShow: true, // will always show the root menu
  name: 'Permission',
  meta: {
    title: '集成测试',
    icon: 'exit-fullscreen',
    roles: ['admin', 'editor'] // you can set roles in root nav
  },
  children: [{
    path: 'home',
    component: () => import('@/views/auto_report/index'),
    name: '仪表盘',
    meta: {
      title: '仪表盘',
      roles: ['admin', 'editor'], // or you can only set roles in sub nav
      affix: true
    }
  },
  {
    path: 'tasklist',
    component: () => import('@/views/a_monitor/index'),
    name: 'CI_任务管理',
    meta: {
      title: 'CI_任务管理',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  },
  {
    path: 'caselist',
    component: () => import('@/views/auto_case/index'),
    name: 'CI_用例仓库',
    meta: {
      title: 'CI_用例仓库',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  },
  {
    path: 'ci_report',
    component: () => import('@/views/ci_report/index'),
    name: '报告详情',
    hidden: true,
    meta: {
      title: '报告详情',
      roles: ['admin', 'editor']
    }
  },
  {
    path: 'node_manage',
    component: () => import('@/views/node_manage/index'),
    name: 'CI_节点管理',
    meta: {
      title: 'CI_节点管理',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  }
  ]
},
{
  path: '/qualitymanagement',
  component: Layout,
  redirect: '/qulity/list',
  alwaysShow: true, // will always show the root menu
  name: '质量',
  meta: {
    // title: '质量管理',
    title: '项目管理',
    icon: 'guide',
    roles: ['admin', 'editor'] // you can set roles in root nav
  },
  children: [
  //   {
  //   path: 'qulity',
  //   component: () => import('@/views/quality/quality-sdata'),
  //   name: '质量数据标准',
  //   meta: {
  //     title: '质量数据标准'
  //     // if do not set roles, means: this page does not require permission
  //   }
  // },
  // {
  //   path: 'prostatistics',
  //   component: () => import('@/views/quality/project-statistics'),
  //   name: '项目统计(周)',
  //   meta: {
  //     title: '项目统计(周)',
  //     roles: ['admin', 'editor']
  //     // if do not set roles, means: this page does not require permission
  //   }
  // },
  // {
  //   path: 'bug_calculate',
  //   component: () => import('@/views/quality/bug-calculates'),
  //   name: 'bug率计算',
  //   meta: {
  //     title: 'bug率计算',
  //     roles: ['admin'] // or you can only set roles in sub nav
  //   }
  // },
  // {
  //   path: 'bug-calcuDay',
  //   component: () => import('@/views/quality/bug-calcuDay'),
  //   name: 'bug率统计(天)',
  //   meta: {
  //     title: 'bug率统计(天)',
  //     roles: ['admin'] // or you can only set roles in sub nav
  //   }
  // },

    {
      path: 'quality-statistics',
      component: () => import('@/views/project-quality/quality-statistics'),
      name: '质量统计',
      meta: {
        title: '质量统计',
        roles: ['admin', 'editor'] // or you can only set roles in sub nav
      }
    },
    {
      path: 'project-list',
      component: () => import('@/views/project-quality/project-list'),
      name: '项目列表',
      meta: {
        title: '项目列表',
        roles: ['admin', 'editor'] // or you can only set roles in sub nav
      }
    }, {
      path: 'quality_visualization',
      component: () => import('@/views/quality_visualization/index'),
      name: 'bug统计',
      meta: {
        title: 'bug统计',
        roles: ['admin', 'editor'] // or you can only set roles in sub nav
      }
    }

  ]
},
{
  path: '/efficiency',
  component: Layout,
  // redirect: '/task/list',
  alwaysShow: true, // will always show the root menu
  name: '能效工具',
  meta: {
    title: '能效工具',
    icon: 'dashboard',
    roles: ['admin'] // you can set roles in root nav
  },
  children: [{
    path: 'timing_task',
    component: () => import('@/views/auto_task/index'),
    name: '计划任务管理',
    meta: {
      title: '计划任务管理',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  }
    // ,
    // {
    //   path: 'list',
    //   component: () => import('@/views/tools/index'),
    //   name: 'demo',
    //   meta: {
    //     title: 'demo',
    //     roles: ['admin'] // or you can only set roles in sub nav
    //   }
    // }
  ]
},
// {
//   path: '/Project',
//   component: Layout,
//   // redirect: '/task/list',
//   alwaysShow: true, // will always show the root menu
//   name: '项目统计',
//   meta: {
//     title: '项目情况',
//     icon: 'dashboard',
//     roles: ['admin', 'editor'] // you can set roles in root nav
//   },
//   children: [{
//     path: 'quality-statistics',
//     component: () => import('@/views/project-quality/quality-statistics'),
//     name: '质量统计',
//     meta: {
//       title: '质量统计',
//       roles: ['admin', 'editor'] // or you can only set roles in sub nav
//     }
//   },
//   {
//     path: 'project-list',
//     component: () => import('@/views/project-quality/project-list'),
//     name: '项目列表',
//     meta: {
//       title: '项目列表',
//       roles: ['admin', 'editor'] // or you can only set roles in sub nav
//     }
//   }
//   ]
// },
{
  path: '/demo',
  component: Layout,
  hidden: true,
  redirect: '/test/index',
  alwaysShow: true, // will always show the root menu
  name: '没东西',
  meta: {
    title: '测试demo',
    icon: 'lock',
    roles: ['admin', 'editor'] // you can set roles in root nav
  },
  children: [{
    path: 'test',
    component: () => import('@/views/test/haha'),
    name: '没东西1111',
    meta: {
      title: '没东西111title',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  },
  {
    path: 'testget',
    component: () => import('@/views/test/get-index'),
    name: 'get请求-title',
    meta: {
      title: 'get请求'
      // if do not set roles, means: this page does not require permission
    }
  },
  {
    path: 'testergou',
    component: () => import('@/views/test/get_case_list'),
    name: '二狗测试',
    meta: {
      title: '二狗测试'
      // if do not set roles, means: this page does not require permission
    }
  },
  {
    path: 'testpost',
    component: () => import('@/views/test/post-index'),
    name: 'post请求-title',
    meta: {
      title: 'post请求'
      // if do not set roles, means: this page does not require permission
    }
  },
  {
    path: 'auto-report',
    component: () => import('@/views/auto_report/index'),
    name: '自动化报告-title',
    meta: {
      title: '自动化报告'
      // if do not set roles, means: this page does not require permission
    }
  }
  ]
},
{
  path: '/icon',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index',
    component: () => import('@/views/icons/index'),
    name: 'Icons',
    meta: { title: 'Icons', icon: 'icon', noCache: true }
  }]
},
// tableRouter,
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
